import { _decorator, Component, Node } from 'cc';
import { Block } from './Block';
import { LBlockADsorptionEffect } from './LBlockADsorptionEffect';
import { GridController } from './GridController';
import ChessboardState from './ChessboardState';
const { ccclass, property } = _decorator;

@ccclass('Level')
export class Level extends Component {
    @property(GridController)
    gridController: GridController;

    start() {
        ChessboardState.init(this.gridController.sizeGrid.x, this.gridController.sizeGrid.z)
        for (let index = 0; index < this.node.children.length; index++) {
            let node = this.node.children[index];
            if (node.getComponent(Block)) {
                let indexs = this.getTouchCurModelNodeTileIndex(node);
                ChessboardState.clearValue(node.name);
                indexs.forEach(item => {
                    ChessboardState.setBoard(item.x, item.z, node.name)
                })
            }
        }
        console.log(ChessboardState.getBoard(), 'Level 设置模拟棋盘数据')

        // let indexs = this.getTouchCurModelNodeTileIndex();
        // ChessboardState.clearValue(name);
        // indexs.forEach(item => {
        //     ChessboardState.setBoard(item.x, item.z, name)
        // })
    }
    getTouchCurModelNodeTileIndex(blockNode: Node) {
        return new LBlockADsorptionEffect(
            blockNode.getWorldPosition(),
            this.gridController.getTileList(),
            this.gridController.getTopRightPos()
        ).calcBlockChekerBoardPos(blockNode.getComponent(Block).blockDirection)
    }

    //satrt 消除结束 判断是否游戏结束或者失败
    onEliminationEnd() {

    }
    //end 消除结束 判断是否游戏结束或者失败
    update(deltaTime: number) {

    }
}


